#!/bin/bash

# postinst script for driver-network-upf
#
# see: dh_installdeb(1)

#set -e

# summary of how this script can be called:
#        * <postinst> \`configure' <most-recently-configured-version>
#        * <old-postinst> \`abort-upgrade' <new version>
#        * <conflictor's-postinst> \`abort-remove' \`in-favour' <package>
#          <new-version>
#        * <postinst> \`abort-remove'
#        * <deconfigured's-postinst> \`abort-deconfigure' \`in-favour'
#          <failed-install-package> <version> \`removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

PATH=/usr/bin:/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export PATH

if [ "${BASEDIR:=/}" = "/" ]; then
    BASEDIR=""
else
    BASEDIR_OPT="-b $BASEDIR"
fi

case "$1" in
    configure)
        chown root:sys $BASEDIR/kernel
	chown root:sys $BASEDIR/kernel/drv
	chown root:sys $BASEDIR/kernel/drv/amd64
	if [ "$ZONEINST" = "1" ]; then
	    [ -f $BASEDIR/kernel/drv/amd64/upf ] && rm -f $BASEDIR/kernel/drv/amd64/upf
	else
	    chmod 0755 "$BASEDIR/kernel/drv/amd64/upf"
	    chown root:sys "$BASEDIR/kernel/drv/amd64/upf"
	fi
	[ "$ZONEINST" = "1" ] || (grep -c "^upf " $BASEDIR/etc/name_to_major >/dev/null || ( add_drv -n  $BASEDIR_OPT  -i '"usb334,1701" "usb3f0,811c" "usb411,1" "usb411,5" "usb411,9" "usb45e,7a" "usb49f,8511" "usb4bb,904" "usb4bb,913" "usb4bb,93a" "usb506,4601" "usb50d,121" "usb557,2007" "usb56e,200c" "usb56e,4002" "usb56e,4005" "usb56e,400b" "usb56e,4010" "usb56e,abc1" "usb5cc,3000" "usb66b,8b4" "usb66b,200c" "usb66b,2202" "usb66b,2203" "usb66b,2204" "usb66b,2206" "usb66b,400b" "usb67c,1001" "usb707,200" "usb707,201" "usb7a6,986" "usb7a6,1986" "usb7a6,8511" "usb7a6,8513" "usb7a6,8515" "usb7aa,4" "usb7aa,d" "usb7b8,110c" "usb7b8,200c" "usb7b8,4002" "usb7b8,4004" "usb7b8,4007" "usb7b8,400b" "usb7b8,400c" "usb7b8,4102" "usb7b8,4104" "usb7b8,abc1" "usb7c9,b100" "usb83a,1046" "usb83a,5046" "usb83a,b004" "usb846,1020" "usb8d1,3" "usb8dd,986" "usb8dd,987" "usb8dd,988" "usb8dd,8511" "usb951,a" "usbb39,109" "usbb39,901" "usbdb7,2" "usbe66,400c" "usb1044,8002" "usb1342,304" "usb15e8,9100" "usb15e8,9110" "usb2001,200c" "usb2001,4001" "usb2001,4002" "usb2001,4003" "usb2001,400b" "usb2001,4102" "usb2001,abc1"' -m '* 0666 root sys' upf ) )
	[ "$ZONEINST" = "1" ] || (grep -c "'upf 0666 root sys'" $BASEDIR/etc/minor_perm >/dev/null || update_drv -n  -a $BASEDIR_OPT  -m 'upf 0666 root sys' clone)
	
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument '$1'" >&2
        exit 1
    ;;
esac



# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

